<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>C++20 module</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../any.html" title="Chapter 4. Boost.Any 1.2">
<link rel="prev" href="ValueType.html" title="ValueType requirements">
<link rel="next" href="../reference_section_of_boost_any.html" title="Reference Section of Boost.Any">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="ValueType.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../any.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../reference_section_of_boost_any.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="any.c_20_module"></a><a class="link" href="c_20_module.html" title="C++20 module">C++20 module</a>
</h2></div></div></div>
<div class="caution"><table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../doc/src/images/caution.png"></td>
<th align="left">Caution</th>
</tr>
<tr><td align="left" valign="top"><p>
        C++20 module support is on early stage, targets, flags and behavior may change
        in the future
      </p></td></tr>
</table></div>
<p>
      If using modern CMake define CMake option <code class="computeroutput"><span class="special">-</span><span class="identifier">DBOOST_USE_MODULES</span><span class="special">=</span><span class="number">1</span></code> to build a C++20 module and make the <code class="computeroutput"><span class="identifier">Boost</span><span class="special">::</span><span class="identifier">any</span></code>
      CMake target provide it. After that an explicit usage of C++20 module <code class="computeroutput"><span class="identifier">boost</span><span class="special">.</span><span class="identifier">any</span></code>
      is allowed:
    </p>
<pre class="programlisting"><span class="identifier">import</span> <span class="identifier">boost</span><span class="special">.</span><span class="identifier">any</span><span class="special">;</span>

<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> <span class="special">{</span>
    <span class="identifier">boost</span><span class="special">::</span><span class="identifier">any</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">42</span><span class="special">;</span>
<span class="special">}</span>
</pre>
<p>
      The <code class="computeroutput"><span class="identifier">Boost</span><span class="special">::</span><span class="identifier">any</span></code> CMake target gives an ability to mix
      includes and imports of the library in different translation units. Moreover,
      if <code class="computeroutput"><span class="identifier">BOOST_USE_MODULES</span></code> macro
      is defined then all the <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">any</span><span class="special">...</span></code>
      includes implicitly do <code class="computeroutput"><span class="identifier">import</span> <span class="identifier">boost</span><span class="special">.</span><span class="identifier">any</span><span class="special">;</span></code> to give all the benefits of modules without
      changing the existing code.
    </p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
        For better compile times make sure that <code class="computeroutput"><span class="identifier">import</span>
        <span class="identifier">std</span><span class="special">;</span></code>
        is available when building the <code class="computeroutput"><span class="identifier">boost</span><span class="special">.</span><span class="identifier">any</span></code> module
        (in CMake logs there should be a 'Using <code class="computeroutput"><span class="identifier">import</span>
        <span class="identifier">std</span><span class="special">;</span></code>'
        message).
      </p></td></tr>
</table></div>
<p>
      If not using CMake, then the module could be build manually from the <code class="computeroutput"><span class="identifier">modules</span><span class="special">/</span><span class="identifier">boost_any</span><span class="special">.</span><span class="identifier">cppm</span></code> file.
    </p>
<p>
      For manual module build the following commands could be used for clang compiler:
    </p>
<pre class="programlisting"><span class="identifier">cd</span> <span class="identifier">any</span><span class="special">/</span><span class="identifier">modules</span>
<span class="identifier">clang</span><span class="special">++</span> <span class="special">-</span><span class="identifier">I</span> <span class="special">../</span><span class="identifier">include</span> <span class="special">-</span><span class="identifier">std</span><span class="special">=</span><span class="identifier">c</span><span class="special">++</span><span class="number">20</span> <span class="special">--</span><span class="identifier">precompile</span> <span class="special">-</span><span class="identifier">x</span> <span class="identifier">c</span><span class="special">++-</span><span class="identifier">module</span> <span class="identifier">boost_any</span><span class="special">.</span><span class="identifier">cppm</span>
</pre>
<p>
      After that, the module could be used in the following way:
    </p>
<pre class="programlisting"><span class="identifier">clang</span><span class="special">++</span> <span class="special">-</span><span class="identifier">std</span><span class="special">=</span><span class="identifier">c</span><span class="special">++</span><span class="number">20</span> <span class="special">-</span><span class="identifier">fmodule</span><span class="special">-</span><span class="identifier">file</span><span class="special">=</span><span class="identifier">boost_any</span><span class="special">.</span><span class="identifier">pcm</span> <span class="identifier">boost_any</span><span class="special">.</span><span class="identifier">pcm</span> <span class="identifier">usage_sample</span><span class="special">.</span><span class="identifier">cpp</span>
</pre>
</div>
<div class="copyright-footer">Copyright © 2001 Kevlin Henney<br>Copyright © 2013-2025 Antony Polukhin<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="ValueType.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../any.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../reference_section_of_boost_any.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
